import {Injectable} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {Http}       from '@angular/http';
import {Router}     from "@angular/router";
import {UserModel}  from "../model/user.model";
import {URLS}       from "../../../common/services/server.url";


@Injectable()
export class UserLoginService {

  constructor(public http: Http,public router:Router) {

  }

  /**
   * 登录系统
   * @param {UserModel} user
   * @returns {Subscription}
   */
  public login(user: UserModel): Observable<any> {
    return this.http.post(URLS.user.login, user);
  }

  public logout(): void {
    localStorage.clear();
    this.router.navigate(['/login']);
  }
}

